#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
资金 - 延期资金管控开通功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.fund_deferred_service import FundService
from jlpay.model.fund_deferred import DeferredActivationOpenRequest


class DeferredActivationOpenExample(BaseExample):
    """延期资金管控开通示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.fund.deferred.activation.open")
        # 创建FundService实例
        self.fund_service = FundService(self.config)
    
    def build_deferred_activation_open_request(self):
        """构建延期资金管控开通请求"""
        request = DeferredActivationOpenRequest()
        
        # 设置请求参数
        request.set_merch_no("849551860110001")
        request.set_agreement_pic("jlpay-test/managefile/2024/02/28/1709081506952_af4f376e39d64abeb5dfb8a0c6db0da7.png")
        
        return request
    
    def demo(self):
        """执行延期资金管控开通示例"""
        self.logger.info("开始执行延期资金管控开通示例")
        
        # 创建延期资金管控开通请求
        request = self.build_deferred_activation_open_request()
        
        # 发送请求并处理响应
        response = self.send_request_and_handle_response(
            self.fund_service.open_deferred_activation,
            "延期资金管控开通",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")
        
        self.logger.info("延期资金管控开通示例执行完毕")


if __name__ == "__main__":
    logger = DeferredActivationOpenExample().logger
    logger.info("==================================================")
    logger.info("===== 延期资金管控开通示例 开始 =====")
    logger.info("==================================================")
    
    example = DeferredActivationOpenExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 延期资金管控开通示例执行完毕 =====")
    logger.info("==================================================") 